package cn.swust.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import cn.swust.model.UserBean;

public class CookieUtil {
	public static Cookie addCookie(String name,String value)
	{
	      Cookie cookie = new Cookie(name, value);   
	        cookie.setMaxAge(60 * 60 * 24 * 14);// cookie保存两周  
	        return cookie;  
	   }
	/**
	 * flag 为1表示情况所有cookie ,0表示清空key
	 * @param request
	 * @param key
	 * @param flag
	 */
	public static void delCookie(HttpServletRequest request,String key,int flag){
		Cookie cookies[] = request.getCookies();
		if(flag==1&&cookies!=null){
			for(Cookie cookie :cookies){
				cookie.setValue("");
				cookie.setMaxAge(0);
			}
		}
	}
}
